<?php
// +----------------------------------------------------------------------
// | INPHP
// | Copyright (c) 2023 https://inphp.cc All rights reserved.
// | Licensed ( https://opensource.org/licenses/MIT )
// | Author: 幺月儿(https://gitee.com/lulanyin) Email: inphp@qq.com
// +----------------------------------------------------------------------
// | scene
// +----------------------------------------------------------------------
namespace app\sso\model;

use Inphp\Core\Db\PDO\Model;
use Inphp\Core\Modules;

class SceneModel extends Model
{
    /**
     * 表名
     * @var string
     */
    protected string $tableName = "sso_scene";

    /**
     * 主键字段
     * @var string
     */
    protected string $primaryKey = "id";

    /**
     *
     * @param string $hash
     * @return string|null
     */
    public static function getHash(string $hash): ?string
    {
        $row = self::emptyQuery()
            ->where("`hash`", $hash)
            ->first();
        return !empty($row) ? $row["scene"] : null;
    }

    /**
     * 保存
     * @param string $scene
     * @return string|null
     */
    public static function saveScene(string $scene): ?string
    {
        $hash = md5($scene);
        $data = [
            "scene"     => $scene,
            "hash"      => $hash
        ];
        return self::emptyQuery()->insert($data) ? $hash : null;
    }
}